package com.pers.springcloud.config;

import com.pers.springcloud.filter.MyGlobalFilter;
import org.springframework.cloud.gateway.route.RouteLocator;
import org.springframework.cloud.gateway.route.builder.RouteLocatorBuilder;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @Author: 黄建
 * @Date: 2020/3/10 15:37
 */
@Configuration
public class GatewayConfig {

    @Bean
    public MyGlobalFilter myGatewayFilter(){
        return new MyGlobalFilter();
    }

    @Bean
    public RouteLocator routeLocator(RouteLocatorBuilder builder){
        RouteLocatorBuilder.Builder routes = builder.routes();
        routes.route("path_route_gn",r -> r.path("/guonei").uri("http://news.baidu.com/")).build();
        routes.route("path_route_gj",r -> {
            return r.path("/guoji").and().host("**.gateway.com:9527").uri("http://news.baidu.com/");
        }).build();
        return routes.build();
    }
}
